var t = getApp();

Page({
    data: {
        car_number: "",
        integral: "积分",
        warnText: "兑换优惠券",
        point: "---",
        list: [],
        page: 1,
        isLoadMore: !0,
        total_page: 0,
        radioIndex: "",
        disabledInquire: !0
    },
    onLoad: function(t) {
        if (this.options.num) {
            this.getData();
            var a = wx.getStorageSync("integral");
            a && this.setData({
                integral: a
            });
        } else wx.showModal({
            title: "提示",
            showCancel: !1,
            content: "请先填写车牌号！",
            success: function(t) {
                t.confirm && wx.navigateTo({
                    url: "/packageI/parkCouponFree/index/index"
                });
            }
        });
    },
    getData: function() {
        var a = this, n = t.getNetAddresss("plugin.parking-pay.frontend.coupon.couponList");
        t._postNetWork({
            url: n,
            data: {},
            success: function(t) {
                var n = t.data;
                1 == n.result ? a.setData({
                    car_number: a.options.num,
                    point: n.data.point,
                    list: n.data.list.data,
                    total_page: n.data.list.last_page,
                    isLoadMore: !0
                }) : wx.showToast({
                    icon: "none",
                    title: n.msg,
                    duration: 1e3
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    onReady: function() {},
    onChange: function(t) {
        this.setData({
            radioIndex: t.detail,
            disabledInquire: !1
        }), Number(this.data.list[t.detail].point) > Number(this.data.point) && this.setData({
            disabledInquire: !0,
            warnText: "积分不足"
        });
    },
    exchangeCoupon: function() {
        var t = this;
        wx.showModal({
            title: "提示",
            content: "是否确认车牌".concat(this.options.num, "，兑换【").concat(this.data.list[this.data.radioIndex].name, "】？"),
            success: function(a) {
                a.confirm && t.confirmExchange();
            }
        });
    },
    confirmExchange: function() {
        var a = t.getNetAddresss("plugin.parking-pay.frontend.coupon.exchangeCoupon");
        t._postNetWork({
            url: a,
            data: {
                id: this.data.list[this.data.radioIndex].id,
                car_number: this.options.num
            },
            success: function(t) {
                var a = t.data;
                1 == a.result ? wx.navigateTo({
                    url: "/packageI/parkCouponFree/index/index?tab=1"
                }) : wx.showToast({
                    icon: "none",
                    title: a.msg,
                    duration: 1e3
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    _getMoreData: function() {
        var a = this;
        if (this.data.isLoadMore = !1, !(this.data.page >= this.data.total_page)) {
            this.data.page += 1;
            var n = t.getNetAddresss("plugin.parking-pay.frontend.coupon.couponList");
            n += "&page=".concat(this.data.page), t._postNetWork({
                url: n,
                success: function(t) {
                    var n = t.data;
                    if (a.data.isLoadMore = !0, 1 === n.result) {
                        var o = n.data.list.data, e = a.data.list.concat(o);
                        a.setData({
                            list: e
                        });
                    } else a.data.page = a.data.page - 1, a.data.isLoadMore = !1;
                }
            });
        }
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {
        this.data.isLoadMore && this._getMoreData();
    },
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});